import 'package:backend.core/core/domain/entities/api/web/yookassa/api_yookassa_transaction_revocation_info.dart';
import 'package:backend.core/core/domain/entities/web/yookassa/yookassa_transaction_revocation_info.dart';
import 'package:backend.purchases/domain/helpers/api/create_api_money_amount_from_internal_one.dart';

abstract class CreateApiYookassaTransactionRevocationInfoFromInternalOne {
  ApiYookassaTransactionRevocationInfo call({
    required YookassaTransactionRevocationInfo revocationInfo,
  });
}

class CreateApiYookassaTransactionRevocationInfoFromInternalOneImpl
    implements CreateApiYookassaTransactionRevocationInfoFromInternalOne {
  const CreateApiYookassaTransactionRevocationInfoFromInternalOneImpl({
    required CreateApiMoneyAmountFromInternalOne createApiMoneyAmountFromInternalOne,
  }) : _createApiMoneyAmountFromInternalOne = createApiMoneyAmountFromInternalOne;

  final CreateApiMoneyAmountFromInternalOne _createApiMoneyAmountFromInternalOne;

  @override
  ApiYookassaTransactionRevocationInfo call({
    required YookassaTransactionRevocationInfo revocationInfo,
  }) {
    final apiRefundedAmount = _createApiMoneyAmountFromInternalOne(
      moneyAmount: revocationInfo.refundedAmount,
    );

    return ApiYookassaTransactionRevocationInfo(
      time: revocationInfo.time,
      refundedAmount: apiRefundedAmount,
    );
  }
}
